package com.lagou.homework_1_3;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class ListTest {

    public static void main(String[] args) {

        //new List 对象
        List lt1 = new ArrayList();

        //new 三个员工信息
        Worker wo1 = new Worker("凤姐",18,20000);
        Worker wo2 = new Worker("欧阳锋",60,8000);
        Worker wo3 = new Worker("刘德华",40,30000);

        //在list集合中增加3位员工
        lt1.add(wo1);
        lt1.add(wo2);
        lt1.add(wo3);
        System.out.println("增加3个员工后"+lt1);

        System.out.println("---------------------------------");

        //在欧阳锋之前插入一个员工
        Worker wo4 = new Worker("张柏芝",35,3300);
        lt1.add(1,wo4);
        System.out.println("插入一个员工后"+lt1);

        System.out.println("---------------------------------");

        //删除员工'刘德华'的信息
        lt1.remove(3);
        System.out.println(lt1);

        System.out.println("---------------------------------");

        //利用foreach循环遍历，打印list中所有的员工
        for (Object obj:lt1) {
            System.out.println(obj);
        }

        System.out.println("---------------------------------");

        //利用 for 循环遍历，打印list中所有的员工
        for (int i =0; i<lt1.size();i++){
            System.out.println(lt1.get(i));
        }

        System.out.println("---------------------------------");

        //利用迭代器遍历，对list中所有的员工调用work方法
        Iterator iterator1 = lt1.iterator();
        while (iterator1.hasNext()){
            Object obj = iterator1.next();
            Worker wo5 = new Worker();
            wo5 = (Worker) obj;
            wo5.work();
        }

        System.out.println("-----------------------");
        //测试重写后的equals方法

        Worker wo6 = new Worker("张柏芝",35,3300);
        Boolean b1 = wo4.equals(wo6);
        System.out.println("测试wo4与wo6是否相等"+ b1);

        b1 = wo4.equals(wo1);
        System.out.println("测试wo4与wo1是否相等"+ b1);


    }
}
